<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="../js/ajaxfileupload.js"></script>
    <script type="text/javascript">
        function fileUpload() {
            $.ajaxFileUpload({
                    url: '../admin/fileUpload', //用于文件上传的服务器端请求地址   调用后端接口（interface）
                    fileElementId: 'fileID', //文件上传域的ID
                    dataType: 'json', //返回值类型 一般设置为json
                    success: function (data) {
                        console.log(data.data.newFileName);
                        var account = window.sessionStorage.getItem("account");
                        var imgsrc = "http://127.0.0.1:8080/userImg/" + account + "/" + data.data.newFileName;
                        window.parent.document.getElementById("imgId").innerHTML = "<img src = '" + imgsrc + "' width='50' height='50'/>";
                    }
                }
            )
        }
    </script>
</head>
<body>
上传用户头像
<input type="file" name="fileName" accept=".jpg,.png,.gif" id="fileID">
<input type="button" value="上传" onclick="fileUpload()">
</body>
</html>